package officialpgk

import (
	"fmt"
	"sort"
)

type User struct {
	Id int
	Name string
	Age int
}

type Users []User

func (u Users) Less(i,j int) bool {
	return u[i].Age<u[j].Age
}

func (u Users) Len() int {
	return len(u)
}

func (u Users) Swap(i,j int)  {
	u[i],u[j]=u[j],u[i]
}

func UserInit()  {
	u:=Users{
		User{
			Id:   1,
			Name: "张三",
			Age:  1,
		},
		User{
			Id:   2,
			Name: "李四",
			Age:  4,
		},
		User{
			Id:   3,
			Name: "王五",
			Age:  3,
		},
	}
	fmt.Println("default",u)
	sort.Sort(u)

	fmt.Println("isSort",sort.IsSorted(u))
	fmt.Println("sorted",u)
}
